<script setup>
import { onMounted, nextTick, ref } from 'vue';
import HelloWorld from './components/HelloWorld.vue'
import useUserInfoStore from '@/stores/userinfo.js'
import axios from 'axios'

onMounted(() => {
  // const element = document.querySelector(".t-b");
  // let start, previousTimeStamp;
  // let done = false;

  // function step(timestamp) {
  //   if (start === undefined) {
  //     start = timestamp;
  //   }
  //   const elapsed = timestamp - start;

  //   if (previousTimeStamp !== timestamp) {
  //     // 这里使用 Math.min() 确保元素在恰好位于 200px 时停止运动
  //     const count = Math.min(0.1 * elapsed, 200);
  //     element.style.transform = `translateX(${count}px)`;
  //     if (count === 200) done = true;
  //   }

  //   if (elapsed < 2000) {
  //     // 2 秒之后停止动画
  //     previousTimeStamp = timestamp;
  //     if (!done) {
  //       window.requestAnimationFrame(step);
  //     }
  //   }
  // }

  // window.requestAnimationFrame(step);
})
let tb = ref('t-b')
onMounted(() => {
  tb.value = 't-b2'
  nextTick(() => {
    const el = document.querySelector('.t-b')
    console.log('nextTick', el.innerHTML);
  })

  // let r = null
  // new Promise(resolve => {
  //   r = resolve
  // }).then(data => {
  //   console.log('拿到了登录数据', data);
  //   const userInfo = useUserInfoStore()
  //   userInfo.userinfo = data

  //   axios.post('/a/b', {
  //     a: 1,
  //     b: 2,
  //   })
  // })

  // setTimeout(() => {
  //   console.log('登录成功');
  //   r({
  //     user: {
  //       name: 'Mark Liu',
  //       favorite: 'games'
  //     }
  //   })
  // }, 1500);
})

</script>

<template>
  <div id="app">
    <header>
      <img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />

      <div class="wrapper">
        <HelloWorld msg="You did it!" />

        <nav>
          <router-link to="/">Home</router-link>
          <router-link to="/about">About</router-link>
          <router-link to="/message-box">MessageBox</router-link>
          <router-link to="/el-table-demo">ElTableDemo</router-link>
          <router-link to="/my-el-dialog">My-El-Dialog_Demo</router-link>
          <router-link to="/transition-demo">TransitionDemo</router-link>
        </nav>
        <div class="t-b inline-block">
          {{ tb }}
        </div>
      </div>
    </header>

    <router-view />
  </div>
</template>

<style scoped>
@keyframes move {
  0% {
    transform: translateX(0px);
  }

  100% {
    transform: translateX(200px);
  }
}

.t-b {
  animation-name: move;
  animation-duration: 1s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}


header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}
</style>
